<?php

class UserAddressTest extends BaseTest
{
    public function testInsert()
    {
        $class = new \Orm\UserAddress\UserAddressClass();
		$class['uid'] = $this->testNum();
		$class['province_id'] = $this->testNum();
		$class['city_id'] = $this->testNum();
		$class['area_id'] = $this->testNum();
		$class['province'] = $this->testStr();
		$class['city'] = $this->testStr();
		$class['area'] = $this->testStr();
		$class['address'] = $this->testStr();
		$class['ship_username'] = $this->testStr();
		$class['ship_mobile'] = $this->testStr();


        $class->insert();
        $result_class = new \Orm\UserAddress\UserAddressClass();
        $result_class->loadById($class['id']);

		$this->assertEquals($class['uid'],$result_class['uid']);
		$this->assertEquals($class['province_id'],$result_class['province_id']);
		$this->assertEquals($class['city_id'],$result_class['city_id']);
		$this->assertEquals($class['area_id'],$result_class['area_id']);
		$this->assertEquals($class['province'],$result_class['province']);
		$this->assertEquals($class['city'],$result_class['city']);
		$this->assertEquals($class['area'],$result_class['area']);
		$this->assertEquals($class['address'],$result_class['address']);
		$this->assertEquals($class['ship_username'],$result_class['ship_username']);
		$this->assertEquals($class['ship_mobile'],$result_class['ship_mobile']);

        return $result_class;
    }

    /**
     * @depends testInsert
     */
    public function testUpdate($class)
    {
		$class['uid'] = $this->testNum();
		$class['province_id'] = $this->testNum();
		$class['city_id'] = $this->testNum();
		$class['area_id'] = $this->testNum();
		$class['province'] = $this->testStr();
		$class['city'] = $this->testStr();
		$class['area'] = $this->testStr();
		$class['address'] = $this->testStr();
		$class['ship_username'] = $this->testStr();
		$class['ship_mobile'] = $this->testStr();


        $class->update();
        $result_class = new \Orm\UserAddress\UserAddressClass();
        $result_class->loadById($class['id']);

		$this->assertEquals($class['uid'],$result_class['uid']);
		$this->assertEquals($class['province_id'],$result_class['province_id']);
		$this->assertEquals($class['city_id'],$result_class['city_id']);
		$this->assertEquals($class['area_id'],$result_class['area_id']);
		$this->assertEquals($class['province'],$result_class['province']);
		$this->assertEquals($class['city'],$result_class['city']);
		$this->assertEquals($class['area'],$result_class['area']);
		$this->assertEquals($class['address'],$result_class['address']);
		$this->assertEquals($class['ship_username'],$result_class['ship_username']);
		$this->assertEquals($class['ship_mobile'],$result_class['ship_mobile']);

        return $result_class;
    }

    /**
     * @depends testUpdate
     */

    public function testDelete($class)
    {
        $class->delete($class['id']);

        $result_class = new \Orm\UserAddress\UserAddressClass();
        $result_class->loadById($class['id']);
        $this->assertEquals(1, $result_class['is_del']);
        return $result_class;
    }


    /**
     * @depends testInsert
     */
    public static function testClean($class)
    {
        if ($class['id']) {
            $class->realDelete($class['id']);
        }
    }
}